package com.netbetter.langzheng.plugin.fileManager.data;

import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.URL;
import com.netbetter.langzheng.plugin.fileManager.dto.CommandDTO;
import com.netbetter.langzheng.plugin.fileManager.model.FileModel;

/**
 * 所有远程请求集散地
 * 
 * @author 嘉陵江里捉鱼
 */
public class FileManagerRequest {

    /**
     * file info requestion
     * 
     * @param model
     * @return
     */
    public static RequestBuilder getFolderInfo(FileModel model) {
        String url = "/info/leftTreeview_info?is_directory=true&parent_id=";
        if (model == null) {
            url += "root";
        } else {
            url += model.getId();
        }
        return new RequestBuilder(RequestBuilder.GET, URL.encode(url));
    }

    public static RequestBuilder getFileInfo(FileModel model) {
        String url = "/info/leftTreeview_info?parent_id=";
        if (model == null) {
            url += "-1";
        } else {
            url += model.getId();
        }
        return new RequestBuilder(RequestBuilder.GET, URL.encode(url));
    }

    public static RequestBuilder exceCommand(CommandDTO command) {
        String url = "/command/exec?" + "data=" + command.toString();
        return new RequestBuilder(RequestBuilder.GET, URL.encode(url));
    }
}
